<script setup>
// import { ref } from 'vue'
import { reactive } from 'vue'
import { loginTo } from '@/services/user.js'
import { message } from 'ant-design-vue'
import { useRouter } from 'vue-router'
import { useToken } from '@/stores/index.js'
const loginForm = reactive({
  // 手机号 密码  是否同意
  username: 'demo', // 这是我们的系统默认账号- 目的是让各位直接可以登录
  password: 'zh@hm#23'
})

const router = useRouter()
const onFinish = async (value) => {
  const { token } = await loginTo(value) //请求登录接口
  const { setToken } = useToken() //结构出储存token的方法
  setToken(token) // 更新pinia里面的token
  message.success('登录成功') //提醒成功
  router.push('/') //跳转到主界面
}
</script>

<template>
  <div class="login-container">
    <div class="logo" style="width: 60vw">
      <img src="@/assets/login.png" style="height: 100%" alt="" />
    </div>
    <div class="form">
      <h3>智慧园区-登录</h3>
      <a-card class="login-card">
        <a-form :model="loginForm" @finish="onFinish">
          <div style="font-size: 16px; color: #8b929d; margin-bottom: 5px">账号</div>
          <a-form-item
            name="username"
            :rules="[{ required: true, message: '账号不能为空', trigger: 'blur' }]"
          >
            <a-input v-model:value="loginForm.username" placeholder="请输入用手机号"></a-input>
          </a-form-item>
          <div style="font-size: 16px; color: #8b929d; margin-bottom: 5px">密码</div>
          <a-form-item
            name="password"
            :rules="[{ required: true, message: '密码不能为空', trigger: 'blur' }]"
          >
            <a-input-password
              v-model:value="loginForm.password"
              placeholder="请输入密码"
            ></a-input-password>
          </a-form-item>
          <a-form-item>
            <a-checkbox>记住我</a-checkbox>
          </a-form-item>
          <a-form-item>
            <a-button type="primary" block html-type="submit">登录</a-button>
            <br />
          </a-form-item>
        </a-form>
      </a-card>
    </div>
  </div>
</template>

<style lang="less" scoped>
.login-container {
  display: flex;
  //   align-items: stretch;
  height: 100vh;
  .tu {
    width: 864px;
    height: 100vh;
  }
  img {
    width: 100%;
    height: 99.9%;
  }
  .form {
    flex: 2;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding-left: 120px;
    .ant-card {
      width: 350px;
      border: none;
      padding: 0;
    }
    h3 {
      padding-left: 30px;
      font-size: 24px;
    }
  }
}
</style>
